package com.bwie.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.TbPaymentMapper;
import com.bwie.pojo.TbPayment;
import com.bwie.service.TbPaymentService;
import com.bwie.utils.R;
import com.bwie.vo.TbPaymentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.UUID;

@Service
@Transactional
public class TbPaymentServiceImpl extends ServiceImpl<TbPaymentMapper, TbPayment> implements TbPaymentService {

@Autowired
TbPaymentMapper tbPaymentMapper;

/**
 * @description: 支付订单生成
 * @author: xushuaihang
 * @Date:   14:32
 * @param:
 * @param tbPaymentVo
 * @return: com.bwie.utils.R
**/
    @Override
    public R addTbPayment(TbPaymentVo tbPaymentVo) {

        TbPayment tbPayment = BeanUtil.toBean(tbPaymentVo, TbPayment.class);

        tbPayment.setCreateTime(new Date());

        String number = "bw"+UUID.randomUUID().toString().substring(0,4);

        tbPayment.setOrderNumber(number);

        tbPaymentMapper.insert(tbPayment);

        return R.ok().message("支付成功！");
    }
}
